package com.oreilly.ez.fileserver.web;

import com.oreilly.ez.fileserver.base.R;
import com.oreilly.ez.fileserver.entity.NoteArticle;
import com.oreilly.ez.fileserver.entity.NoteArticleVO;
import com.oreilly.ez.fileserver.service.INoteArticleService;
import com.oreilly.ez.fileserver.service.INoteArticleService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api
@CrossOrigin
@RestController
@RequestMapping("/noteArticles")
public class NoteArticleCtrl extends BaseCtrl<NoteArticle> {

    @Autowired
    private INoteArticleService noteArticleService;

    @Override
//    Object find(NoteArticle item, @PageableDefault(sort = {"ctime"}, direction = Sort.Direction.DESC) Pageable pageable) throws Exception {
    Object find(NoteArticle item, @PageableDefault Pageable pageable) throws Exception {
//        Page<NoteArticle> page = noteArticleService.find(item, pageable);
        Page<NoteArticleVO> page = noteArticleService.findVO(item, pageable);
        return R.ok(page);
    }

    @Override
    Object findById(@PathVariable String id) throws Exception {
        NoteArticle item = noteArticleService.findById(id);
        return R.ok(item);
    }

    @Override
    Object add(@RequestBody  NoteArticle item) throws Exception {
         noteArticleService.add(item);
         return R.ok(item);
    }

    @Override
    Object update(@RequestBody NoteArticle item) throws Exception {
        noteArticleService.update(item);
        return R.ok(item);
    }

    @Override
    Object delete(String[] ids) throws Exception {
        noteArticleService.deleteByIds(ids);
        return R.ok("delete ok");
    }
}
